import Vue from 'vue'
import Router from 'vue-router'

const App = () => import ('@/App')
const Main = () => import('@/page/main/Main')

const Home = () => import('@/page/home/Home')
const Search = () => import('@/page/home/Search')
const Detail = () => import('@/page/home/Detail')

const Chat = () => import('@/page/chat/Chat')
const ChatRecord = () => import('@/page/chat/ChatRecord')
const Contract = () => import('@/page/chat/Contract')

const Order = () => import('@/page/order/Order')

const Push = () => import('@/page/push/Push')

const User = () => import('@/page/user/User')
const Profile = () => import('@/page/user/Profile')
const ChangePhone = () => import('@/page/user/ChangePhone')
const Policies = () => import('@/page/user/Policies')

const Login = () => import('@/page/login/Login')
const Register = () => import('@/page/login/Register')
const Forget = () => import('@/page/login/Forget')

Vue.use(Router)

export default new Router({
  mode: 'hash',
  routes: [
    {
      // 顶层路由
      path: '/',
      component: App,
      children: [
        // 地址为空跳转
        {
          path: '',
          redirect: '/main'
        },

        // 控制视图切换
        {
          path: '/main',
          component: Main,
          children: [
            // 地址为空跳转
            {
              path: '',
              redirect: '/home'
            },
            // 房源列表页
            {
              path: '/home',
              name: 'home',
              component: Home,
              meta: {
                index: 0
              }
            },

            // 房源搜索
            {
              path: '/search',
              name: 'search',
              component: Search,
              meta: {
                index: 10
              }
            },

            // 房源发布页
            {
              path: '/push',
              name: 'push',
              component: Push,
              meta: {
                index: 30
              }
            },

            // 用户信息页
            {
              path: '/user',
              name: 'user',
              component: User,
              meta: {
                index: 40
              }
            },

            // 用户信息详情页
            {
              path: '/user/profile',
              name: 'profile',
              component: Profile,
              meta: {
                index: 41
              }
            },

            // 更换绑定手机
            {
              path: '/user/changePhone',
              name: 'changePhone',
              component: ChangePhone,
              meta: {
                index: 42
              }
            },

            // 服务条例
            {
              path: '/user/policies',
              name: 'policies',
              component: Policies,
              meta: {
                index: 43
              }
            },

            // 聊天列表
            {
              path: '/user/chatRecord',
              name: 'chatRecord',
              component: ChatRecord,
              meta: {
                index: 44
              }
            },

            // 订单列表
            {
              path: '/user/order',
              name: 'order',
              component: Order,
              meta: {
                index: 45
              }
            }
          ]
        },

        // 登录页
        {
          path: '/login',
          name: 'login',
          component: Login,
          meta: {
            index: 100
          }
        },

        // 忘记密码
        {
          path: '/forget',
          name: 'forget',
          component: Forget,
          meta: {
            index: 101
          }
        },

        // 注册页面
        {
          path: '/register',
          name: 'register',
          component: Register,
          meta: {
            index: 102
          }
        },

        // 房屋详情
        {
          path: '/detail',
          name: 'detail',
          component: Detail,
          meta: {
            index: 200
          }
        },

        // 沟通页
        {
          path: '/chat',
          name: 'chat',
          component: Chat,
          meta: {
            index: 201
          }
        },

        // 签约页
        {
          path: '/contract',
          name: 'contract',
          component: Contract,
          meta: {
            index: 202
          }
        }
      ]
    }
  ],
  linkActiveClass: 'active'
})
